package de.koller.worlders.render.visual;

import de.koller.worlders.render.util.TextureRep;
import org.lwjgl.opengl.GL11;

public class RotationDRO extends DisplayRenderObject {

	private float rotSpeed = 0;
	private float currentD = 0;
	
	private float u0, v0, u1, v1, u2, v2, u3, v3;
	
	public RotationDRO( TextureRep texture ) {
		super( texture );
	}
	
	@Override
	protected void init() {
		super.init();
		
		wroot.vmap.addForStep( this );
	}
	
	public void set( Object... val ) {
		rotSpeed = (float)val[0];
	}
	
	@Override
	public void step( int elapsedTime ) {
		super.step( elapsedTime );
		
		currentD += rotSpeed * elapsedTime;
		float d = 0.71f;
		
		u0 = (float)Math.cos( currentD + Math.PI/2 ) * d - .5f;
		v0 = (float)Math.sin( currentD + Math.PI/2 ) * d - .5f;
		
		u1 = (float)Math.cos( currentD + Math.PI ) * d - .5f;
		v1 = (float)Math.sin( currentD + Math.PI ) * d - .5f;

		u2 = (float)Math.cos( currentD + 3*Math.PI/2 ) * d - .5f;
		v2 = (float)Math.sin( currentD + 3*Math.PI/2 ) * d - .5f;

		u3 = (float)Math.cos( currentD ) * d - .5f;
		v3 = (float)Math.sin( currentD ) * d - .5f;
	}
	
	@Override
	public void renderObject( float x, float y, float w, float h, float z, boolean fast ) {
		this.renderObject( x, y, w, h, z, fast, u0, v0, u1, v1, u2, v2, u3, v3 );
	}

	@Override
	public void preRendering() {
		GL11.glTexParameteri( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT );
		GL11.glTexParameteri( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT );
		
		preDROSet();
	}
	
	
}
